package com.yazi.mxz.common.db.dao.impl;


import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.yazi.mxz.common.db.dao.MemberDao;
import com.yazi.mxz.common.entity.beans.Member;

import com.myframework.smhj.hibernate.dao.BasicDao;

@Repository("memberDao")
public class MemberDaoImpl extends BasicDao<Member> implements MemberDao {


	public MemberDaoImpl() {
		super(Member.class);
		
	}

	@Override
	public Criteria getExample(Member member, String searchWord) {
		Criteria c = super.getExample(member, searchWord);
		
		// ...关联对象条件
		
		// 关键字条件
		if(null != searchWord && !searchWord.isEmpty()){
			//关键字可查用户名、邮箱、手机号
			String likeWord = "%" + searchWord + "%";
			c.add(Restrictions.or(
					Restrictions.like("name", likeWord),
					Restrictions.or(Restrictions.like("email", likeWord),
							Restrictions.like("mobile", likeWord))));
		}
		
		return c;
	}
	
	@Override
	public Member oneByAccountName(String name) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("name", name);
		return unique("oneByAccountNameHql", param);
	}

}
